package com.wey.springboot.service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wey.springboot.bean.Account;
import com.wey.springboot.mapper.AccountMapper;
import com.wey.springboot.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class AccountService extends ServiceImpl<AccountMapper, Account> {
  @Autowired
  private AccountMapper mapper;

  public Account get(Integer id) {
    return mapper.selectById(id);
  }

  public List<Account> list() {
    return mapper.selectList(Wrappers.emptyWrapper());
  }

  public boolean saveBatch(int count) {
    List<Account> list = new ArrayList<>();
    for (int i = 0; i < count; i++) {
      Account account = new Account();
      account.setName(StringUtil.getRandomWord(5));
      account.setPwd(StringUtil.getRandomString(6));
      account.setAge((int) (Math.random() * 100));
      list.add(account);
    }
    return saveBatch(list);
  }
}
